<!--
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2023-11-29 10:57:44
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2024-01-10 15:42:43
 * @FilePath: \partal\src\views\design\style\color.vue
 * @Description: 设计指南-样式指南
-->

<script lang="ts" setup>
  import Back from '@/components/Back'
  import { showToast } from '@/utils/toast'
  import neutralColor from './src/neutralColor.json'
  import commonColor from './src/commonColor.json'

  /**
   * 监听鼠标移入
   * @param e dom元素
   */
  const onMouseenter = (e: any) => {
    e.target.className = e.target.className.replace(' zoom-out', '')
    e.target.className += ' zoom-in'
  }

  /**
   * 监听鼠标移出
   * @param e dom元素
   */
  const onMouseleave = (e: any) => {
    e.target.className = e.target.className.replace(' zoom-in', '')
    e.target.className += ' zoom-out'
  }

  /**
   * 复制文本
   * @param text 文本内容
   */
  const copyText = (text: string) => {
    navigator.clipboard.writeText(text)
      .then(()=> showToast('复制成功'))
      .catch(() => showToast('复制失败'))
  }
</script>

<template>
  <div class="color">
    <Back class="back"/>
    <p class="p14">SSC+ Design</p>
    <p class="p36 mt18">颜色</p>
    <p class="p14 mt12">组件库内置了一套符合人眼视觉的色彩算法。</p>
    <p class="split mt38" />
    <div class="content-item">
      <p class="content-item-title">简介</p>
      <p class="content-item-desc">SSC+ Design 的基础色板共计 120 个颜色，包含 12 个主色以及衍生色。这些颜色基本可以满足中后台设计中对于颜色的需求。</p>
    </div>
    <div class="main">
      <div class="main-item" v-for="(item, i) in commonColor" :key="`main-item${i}`">
        <p class="main-item-title">{{ item.title }}</p>
        <p class="main-item-subTitle">{{ item.subTitle }}</p>
        <div class="main-item-content">
          <div class="rowContent" :class="subI > 4 ? 'white' : ''" v-for="(subItem, subI) in item.datas" :key="`main-item${i}-row${subI}`" :style="{'background': subItem}" @mouseenter="onMouseenter" @mouseleave="onMouseleave" @click="copyText(subItem)">
            <span class="label">{{ item.color + '-' + (subI + 1) }}</span>
            <span class="value">{{ subItem }}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="neutral">
      <p class="neutral-title">中性色版</p>
      <p class="neutral-desc">功能色的主要作用是向用户明确的传达成功、警告、错误、链接等信息和状态。SSC+基于用户对色彩的通用认知，提供了适合不同状态的功能色及其配套色。</p>
      <div class="neutral-content">
        <div class="neutral-content-item" :class="i > 4 ? 'white' : ''" v-for="(item, i) in neutralColor.datas" :key="`neutral-content-item${i}`" :style="{'background': item}" @mouseenter="onMouseenter" @mouseleave="onMouseleave" @click="copyText(item)">
          <span class="label">{{ neutralColor.color + '-' + (i + 1) }}</span>
          <span class="value">{{ item }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<style type="less" scoped>
  .color {
    position: relative;
    width: 988px;
    margin: auto;
    padding: 36px 0 120px;
    > .back {
      position: absolute;
      top: 48px;
      right: 0;
    }
  }
  .content-item {
    margin-top: 48px;
    > .content-item-title {
      margin-top: 16px;
      font-size: 20px;
      color: #1D2129;
      line-height: 30px;
    }
    > .content-item-desc {
      margin-top: 16px;
      font-size: 14px;
      color: #4E5969;
      line-height: 22px;
      >.blue {
        color: #1677FF;
        cursor: pointer;
      }
    }
  }
  .main {
    display: grid;
    grid-template-columns: 271px 271px 271px;
    grid-template-rows: 530px 530px 530px 530px;
    grid-gap: 96px 22px;
    margin-top: 48px;
    > .main-item {
      width: 271px;
      height: 530px;
      > .main-item-title {
        text-align: center;
        height: 30px;
        font-size: 20px;
        color: #1D2129;
        line-height: 30px;
      }
      > .main-item-subTitle {
        margin-top: 10px;
        text-align: center;
        height: 22px;
        font-size: 14px;
        color: #7A8499;
        line-height: 22px;
      }
      > .main-item-content {
        margin-top: 28px;
        height: 440px;
        > .rowContent {
          height: 44px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          cursor: pointer;

          > .label {
            margin-left: 12px;
            font-size: 14px;
            color: rgba(0, 0, 0, 0.85);
          }
          > .value {
            margin-right: 10px;
            font-size: 12px;
            color: rgba(0, 0, 0, 0.85);
          }
          &.white {
            > .label {
              color: #fff;
            }
            > .value {
              color: #fff;
            }
          }
          &.zoom-in {
            animation: zoom-in 300ms forwards;
          }
          &.zoom-out {
            animation: zoom-out 300ms forwards;
          }
        }
      }
    }
  }
  .neutral {
    margin-top: 48px;
    > .neutral-title {
      height: 30px;
      font-size: 20px;
      color: #1D2129;
      line-height: 30px;
    }
    > .neutral-desc {
      margin-top: 16px;
      height: 22px;
      font-size: 14px;
      color: #4E5969;
      line-height: 22px;
    }
    > .neutral-content {
      height: 86px;
      margin-top: 16px;
      display: flex;
      > .neutral-content-item {
        width: 70px;
        height: 86px;
        display: flex;
        flex-direction: column;
        align-items: center;
        cursor: pointer;
        > .label {
          margin-top: 20px;
          font-size: 14px;
          color: rgba(0, 0, 0, 0.85);
          line-height: 22px;
        }
        > .value {
          margin-top: 10px;
          font-size: 12px;
          color: rgba(0, 0, 0, 0.85);
          line-height: 18px;
        }
        &.white {
          > .label {
            color: #fff;
          }
          > .value {
            color: #fff;
          }
        }
        &.zoom-in {
          animation: zoom-in 300ms forwards;
        }
        &.zoom-out {
          animation: zoom-out 300ms forwards;
        }
      }
    }
  }

  @keyframes zoom-in {
    from {
      transform: scale(1, 1);
    }
    to {
      transform: scale(1.05, 1.05);
    }
  }
  @keyframes zoom-out {
    from {
      transform: scale(1.05, 1.05);
    }
    to {
      transform: scale(1, 1);
    }
  }
</style>
